package com.wanhe.shoppingcart.cuiyu;


import com.wanhe.base.model.base.SallOutDish;
import com.wanhe.base.model.holder.SallOutHolder;
import com.wanhe.base.util.ObjectUtil;
import com.wanhe.shoppingcart.bean.CartItem;
import com.wanhe.shoppingcart.bean.SetMealCartItem;
import com.wanhe.shoppingcart.manager.CartManager;

import java.util.List;

/**
 * 潮牛脆鱼套餐对象
 * @author 陈德基
 * create at 2017/5/14 11:07
 */
public class CuiYuSetMeal extends SetMealCartItem {

	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	private  int position;
	public  double allPrice;

	public double getAllPrice() {
		return allPrice;
	}

	public void setAllPrice(double allPrice) {
		this.allPrice = allPrice;
	}

	@Override
	public double getPrice() {

		double setmealPrice = getDish().getNum_price1();

		double fuliaoPrice = 0;
		List<CartItem> childFoods = getArrChildItem();
		for (int i = 0; i < childFoods.size(); i++) {
			CartItem cartItem = childFoods.get(i);
			if (cartItem instanceof CuiYuPot){
				CuiYuPot setMealCartItem = (CuiYuPot) cartItem;
				List<CartItem> childFoods1 = setMealCartItem.getArrChildItem();
				for (int j = 0; j < childFoods1.size(); j++) {
					fuliaoPrice += childFoods1.get(j).getDish().getNum_price1();
				}
			}
		}

		return setmealPrice + fuliaoPrice;
	}

	@Override
	public String getSignID() {
		String newSignId =  this.getDishGuid() + this.getAddTime();
		return newSignId;
	}

	@Override
	public boolean isSellOut(int count) {
		boolean isSallOut = false;
		SallOutDish sallOutDish = SallOutHolder.getInstance().get(getDish().getCh_dishno());
		if (ObjectUtil.checkObject(sallOutDish)) {
			int itemCount = CartManager.getInstance().getSameGuidItemCount(dish.getDish_guid());
			itemCount += count;
			if (itemCount>= sallOutDish.getWarnNum()) {
				isSallOut = true;

				return isSallOut;
			}
		}

		if (ObjectUtil.checkObjectList(getArrChildItem())){
			for (int i = 0; i < getArrChildItem().size(); i++) {
				CartItem cartItem = getArrChildItem().get(i);
				boolean sallOut = cartItem.isSellOut(count);
				if (sallOut) return sallOut;
			}
		}

		return isSallOut;
	}
}
